/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-09-01
 * Time: 13:52
 */
public class test1 {
    public String longestCommonPrefix(String[] strs) {
        int n = strs.length;
        // 拿到第一个元素
        String prefix = strs[0];
        for(int i=1;i<n;i++){
            // 拿到第i个元素
            String ch = strs[i];
            while(ch.indexOf(prefix)!=0){
                // 切割
                prefix = prefix.substring(0,prefix.length()-1);
                if(prefix.isEmpty()){
                    return "";
                }
            }
        }
        return prefix;
    }
}
